package com.greenline.push.dal.pushcenter.impl;

import java.util.ArrayList;
import java.util.List;

import com.greenline.push.dal.base.BaseDAO;
import com.greenline.push.dal.pushcenter.ClassUserDAO;
import com.greenline.push.dal.pushcenter.dataobject.ClassUserDO;
import com.greenline.push.dal.query.ClassUserQuery;

public class ClassUserDAOImpl extends BaseDAO implements ClassUserDAO {

	@Override
	public Long insert(ClassUserDO classUser) {
		return (Long) super.getSqlMapClientTemplate().insert(
				"classUser.insert", classUser);
	}

	@Override
	public ClassUserDO getClassUserById(Long id) {
		return (ClassUserDO) super.getSqlMapClientTemplate().queryForObject(
				"classUser.find_by_id", id);
	}

	@Override
	public int update(ClassUserDO classUser) {
		return super.getSqlMapClientTemplate().update("classUser.update",
				classUser);
	}

	@Override
	public ClassUserQuery listByQuery(ClassUserQuery query) {
		return (ClassUserQuery) super.listByQuery("classUser.list_by_query",
				query);
	}

	@Override
	public int delete(Long id) {
		return super.getSqlMapClientTemplate().delete("classUser.delete", id);
	}

	@Override
	public int insertUidList(List<Long> uidList, Long classId) {
		int size = uidList.size();
		List<ClassUserDO> list = new ArrayList<ClassUserDO>();
		for (int i = 0; i < size; i++) {
			Long uid = uidList.get(i);
			ClassUserDO userDo = new ClassUserDO();
			userDo.setUserId(uid);
			userDo.setClassId(classId);
			list.add(userDo);
		}
		int rows = super.getSqlMapClientTemplate().update(
				"classUser.insertUidList", list);
		return rows;
	}

}
